import { useState, useCallback } from 'react';

import { company } from '@/api';

export default function useCompany() {
  // 基本信息
  const [baseInfo, setBaseInfo] = useState<any>(undefined);
  const getBaseInfo = useCallback(async (params: { id: string }) => {
    const result = await company.getBasicInfo(params);
    if (result && result.data) {
      setBaseInfo(result.data);
    } else {
      setBaseInfo(undefined);
    }
  }, []);
  const [relationUrl, setRelationUrl] = useState<any[]>([]);
  const getRelationURL = useCallback(async (params: { id: string }) => {
    const result: any = await company.getRelationURL(params);
    if (result && result.url) {
      setRelationUrl(result.url);
    } else {
      setRelationUrl([]);
    }
  }, []);
  const [holderList, setHolderList] = useState<any[]>([]);
  const getHolderList = useCallback(async (params: { id: string }) => {
    const result = await company.getHolderList(params);
    if (result && result.data) {
      setHolderList(result.data);
    } else {
      setHolderList([]);
    }
  }, []);

  const [personalList, setPersonalList] = useState<any[]>([]);
  const getPersonalList = useCallback(async (params: { id: string }) => {
    const result = await company.getPersonalList(params);
    if (result && result.data) {
      setPersonalList(result.data);
    } else {
      setPersonalList([]);
    }
  }, []);

  const [works, setWorks] = useState<any[]>([]);
  const getWorks = useCallback(async (params: { id: string }) => {
    const result = await company.getWorks(params);
    if (result && result.data) {
      setWorks(result.data);
    } else {
      setWorks([]);
    }
  }, []);

  const [software, setSoftware] = useState<any[]>([]);
  const getSoftware = useCallback(async (params: { id: string }) => {
    const result = await company.getSoftware(params);
    if (result && result.data) {
      setSoftware(result.data);
    } else {
      setSoftware([]);
    }
  }, []);

  const [website, setWebsite] = useState<any[]>([]);
  const getWebsite = useCallback(async (params: { id: string }) => {
    const result = await company.getWebsite(params);
    if (result && result.data) {
      setWebsite(result.data);
    } else {
      setWebsite([]);
    }
  }, []);

  const [trademark, setTrademark] = useState<any[]>([]);
  const getTrademark = useCallback(async (params: { id: string }) => {
    const result = await company.getTrademark(params);
    if (result && result.data) {
      setTrademark(result.data);
    } else {
      setTrademark([]);
    }
  }, []);

  const [administrativeLicensing, setAdministrativeLicensing] = useState<any[]>(
    [],
  );
  const getAdministrativeLicensing = useCallback(
    async (params: { id: string }) => {
      const result = await company.getAdministrativeLicensing(params);
      if (result && result.data) {
        setAdministrativeLicensing(result.data);
      } else {
        setAdministrativeLicensing([]);
      }
    },
    [],
  );

  const [administrativeSanction, setAdministrativeSanction] = useState<any[]>(
    [],
  );
  const getAdministrativeSanction = useCallback(
    async (params: { id: string }) => {
      const result = await company.getAdministrativeSanction(params);
      if (result && result.data) {
        setAdministrativeSanction(result.data);
      } else {
        setAdministrativeSanction([]);
      }
    },
    [],
  );

  const [patent, setPatent] = useState<any[]>([]);
  const getPatent = useCallback(async (params: { id: string }) => {
    const result = await company.getPatent(params);
    if (result && result.data) {
      setPatent(result.data);
    } else {
      setPatent([]);
    }
  }, []);

  // 企业经营
  const [manageInfo, setManageInfo] = useState<any[]>([]);
  const getManageInfo = useCallback(async (params: { id: string }) => {
    const result = await company.getManageInfo(params);
    if (result && result.data) {
      setManageInfo(result.data);
    } else {
      setManageInfo([]);
    }
  }, []);

  const [manageData, setManageData] = useState<any>({});
  const getManageData = useCallback(
    async (params: {
      id: string;
      beginDate?: string;
      beginEnd?: string;
      type?: string; // 指标类型
      index?: string; // 指数周期
    }) => {
      const result = await company.getManageData(params);
      if (result && result.data) {
        setManageData(result.data);
      } else {
        setManageData({});
      }
    },
    [],
  );

  // 政策受益
  const [policySituation, setPolicySituation] = useState<any[]>([]);
  const getPolicySituation = useCallback(async (params: { id: string }) => {
    const result = await company.getPolicySituation(params);
    if (result && result.data) {
      setPolicySituation(result.data);
    } else {
      setPolicySituation([]);
    }
  }, []);

  const [policyCenterData, setPolicyCenterData] = useState<any[]>([]);
  const getPolicyCentreData = useCallback(async (params: { id: string }) => {
    const result = await company.getPolicyCentreData(params);
    if (result && result.data) {
      setPolicyCenterData(result.data);
    } else {
      setPolicyCenterData([]);
    }
  }, []);

  const [yearPolicy, setYearPolicy] = useState<any[]>([]);
  const getYearPolicy = useCallback(async (params: { id: string }) => {
    const result = await company.getYearPolicy(params);
    if (result && result.data) {
      setYearPolicy(result.data);
    } else {
      setYearPolicy([]);
    }
  }, []);

  const [outputValue, setOutputValue] = useState<any>({});
  const getOutPutValue = useCallback(async (params: { id: string }) => {
    const result = await company.getOutPutValue(params);
    if (result && result.data) {
      setOutputValue(result.data);
    } else {
      setOutputValue({});
    }
  }, []);

  // 舆情预警
  const [publicSentiment, setPublicSentiment] = useState<any[]>([]);
  const getPublicSentiment = useCallback(async (params: { id: string }) => {
    const result = await company.getPublicSentiment(params);
    if (result && result.data) {
      setPublicSentiment(result.data);
    } else {
      setPublicSentiment([]);
    }
  }, []);

  const [warningMonthData, setWarningMonthData] = useState<any>({});
  const getWarningMonthData = useCallback(
    async (params: { id: string; type: string | number }) => {
      const result = await company.getWarningMonthData(params);
      if (result && result.data) {
        setWarningMonthData(result.data);
      } else {
        setWarningMonthData({});
      }
    },
    [],
  );

  return {
    baseInfo,
    getBaseInfo,
    relationUrl,
    getRelationURL,
    holderList,
    getHolderList,
    personalList,
    getPersonalList,
    works,
    getWorks,
    software,
    getSoftware,
    website,
    getWebsite,
    trademark,
    getTrademark,
    patent,
    getPatent,
    administrativeLicensing,
    getAdministrativeLicensing,
    administrativeSanction,
    getAdministrativeSanction,
    manageInfo,
    getManageInfo,
    manageData,
    getManageData,
    policySituation,
    getPolicySituation,
    policyCenterData,
    getPolicyCentreData,
    yearPolicy,
    getYearPolicy,
    outputValue,
    getOutPutValue,
    publicSentiment,
    getPublicSentiment,
    warningMonthData,
    getWarningMonthData,
  };
}
